<template>
  <div class="container">
    <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
  </div>
</template>

<script>
/**
 * 用于选择工单的关联页面
 */
import { getListApi } from "@/api/orderManagement/experimentOrder";

export default {
  props: {
    searchData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    selectType: {
      type: String,
      default: "",
    },
    selectId: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      tableSetting: {
        radioShow: true,
        showFilterBtn: false,
        showCustomBtn: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "input",
              label: "标题",
              model: "title",
              placeholder: "请输入",
            },
            {
              type: "input",
              label: "编号",
              model: "code",
              placeholder: "请输入",
            },
            {
              type: "dept",
              label: "设备单位",
              model: "deptManageName",
              idsStr: "deptManages",
              placeholder: "请输入",
            },
            {
              type: "select",
              label: "专业",
              model: "major",
              placeholder: "请输入",
              option: this.$store.getters.dirtData("common_major"),
            },
            {
              type: "select",
              label: "状态",
              model: "statusList",
              placeholder: "请输入",
              multiple: true,
              option: this.$store.getters.dirtData("order_all_status"),
            },
            
            {
              type: "dept",
              label: "作业单位",
              model: "deptWorkName",
              idsStr: "deptWork",
              clearable: true,
            },
          ],
        },
        actionList: [],
        column: [
          {
            label: "状态",
            prop: "status",
            formatter: (row) => {
              return this.$store.getters["fineDirtDataName"](
                "order_all_status",
                row.status
              );
            },
            sortable: "custom",
          },
          {
            label: "编号",
            prop: "code",
            sortable: "custom",
          },
          {
            label: "标题",
            prop: "title",
            sortable: "custom",
          },
          {
            label: "设备管理单位",
            prop: "deptManageName",
            sortable: "custom",
          },
          {
            label: "作业单位",
            prop: "workDeptPoList",
            //sortable: "custom",
            scopeType: "formate",
            method: (row) => {
              let worklist = row.workDeptPoList || [];
              let name = [];
              if (worklist.length > 0) {
                worklist.map((i) => {
                  name.push(i.workDeptName);
                });
              }
              return name.toString();
            },
            // showTooltip: true,
            width: "240px",
          },
          {
            label: "工单来源",
            prop: "source",
            formatter: (row) => {
              return this.$store.getters["fineDirtDataName"](
                "order_source",
                row.source
              );
            },
            sortable: "custom",
          },
          {
            label: "创建人",
            prop: "createByName",
            sortable: "custom",
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom",
          },
        ],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            this.$refs.klTable.radioSelect(row);
          },
        },
      },
    };
  },
  created() {
    this.tableSetting.searchObj.queryData = Object.assign(
      this.tableSetting.searchObj.queryData,
      this.searchData
    );
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      if (this.selectType == "overhaul") {
        //大修工单关联试验工单
        //初始化表格
        this.tableSetting.radioShow = false;
        this.tableSetting.selectionShow = true;
        this.tableSetting.searchObj.searchArr.map((i) => {
          if (i.model == "orderType") {
            i.disabled = true;
          }
        });
      }
      this.updateData();
    },
    //更新列表页的数据
    updateData() {
      this.$refs.klTable.searchData();
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      getListApi(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
    //获取选中数据
    getselectData() {
      let data = null;
      if (this.tableSetting.selectionShow) {
        data = this.$refs.klTable.getSelectData();
      } else {
        data = this.$refs.klTable.getRadioData();
      }
      return data;
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  background-color: white;
  display: flex;
  .class-tree {
    height: 100%;
    width: 300px;
    border-top: 10px solid #f2f3f8;
  }
  .detail-content {
    height: 100%;
    width: calc(100% - 300px);
    border-left: 10px solid #f2f3f8;
    border-top: 10px solid #f2f3f8;
    padding: 20px;
    flex: 1;
    //overflow: auto;
  }
}
</style>